import java.util.LinkedList;
import java.util.Queue;

/**
 * @classDesc: 功能描述:()
 * @author: 黄伟成
 * @createTime: 2017/9/21 11:45
 * @version: v1.0
 * @copyright:善林(上海)金融信息服务有限公司
 */
public class QueueUtil {

    private static Queue<Object> queue = new LinkedList<>();

    private static MyThread myThread = null;

    public static void offer(String obj) {
        if (myThread == null) {
            myThread = new MyThread();
            myThread.start();
        }
        queue.offer(obj);
        myThread.setIsstart(true);
    }

    static class MyThread extends Thread {

        static boolean isstart = false;

        public void setIsstart(boolean bo) {
            isstart = bo;
        }

        @Override
        public void run() {
            System.err.println("------1");
            while (true) {
                if (queue.size() != 0) {
                    Object poll = queue.poll();
                    //TODO 业务处理
                    System.err.println("处理:"+poll);
                } else {


                    isstart=false;
                    if (!isstart) {
                        try {
                            System.out.println("3iumian");

                            //Thread.sleep(1000);
                            queue.wait();
                        } catch (InterruptedException e) {

                        }
                    }



                }
            }
        }


    }

}
